public class congress {
    
    private static int seats;
    private static int numberOfStates;
    private static state[] states;
    
    
    public static void max() {
        seats = seats - numberOfStates;
        MaxPQ pq = new MaxPQ(states);
        while(seats > 0) {
            state tmp = pq.delMax();
            tmp.giveSeat();
            tmp.update();
            pq.insert(tmp);
            seats--;
        }
    }
    
    public static void readFile(String file, String file2) {
        In in = new In(file);
        In in2 = new In(file2);
        numberOfStates = Integer.parseInt(in.readLine());
        seats = Integer.parseInt(in.readLine());
        states = new state[numberOfStates];
        int i = 0;
        while(!in.isEmpty()) {
            String name = in.readLine();
            int pop = Integer.parseInt(in.readLine());
            state state = new state(name, pop);
            states[i] = state;
            i++;
        }
        max();
        int j = 0;
        while(!in2.isEmpty() ) {
            String corret = in2.readLine();
            String test = states[j].getName() + " " + states[j].getSeats(); 
            if (!corret.equals(test)) {
                StdOut.println("Fejl");
                StdOut.println(test);
                StdOut.println(corret);
            }
            j++;
        }
        StdOut.println("Done");
    }
    
    public static void main(String[] args) {
        readFile(args[0], args[1]);
    } 
}